offsetted reflections.py (737B)
1 #!/usr/bin/env python2 2 3 import theano.tensor as T 4 5 from relations.base import * 6 7 class Offsetted_reflections(Base_relation): 8 """ Offsetted reflections class. 9 10 This class has two parameters: 11 H -- the hyperplanes 12 O -- the offsets 13 """ 14 def __init__(self, rng, number, dimension, tag): 15 """ Initialise the parameter. """ 16 parameters = [ ('H', (dimension,)), ('O', (1,)) ] 17 super(Offsetted_reflections, self).__init__(rng, number, parameters, tag) 18 19 def apply(self, inputs, h, o): 20 """ Apply the given relations to a given input. """ 21 f = T.addbroadcast((T.sum(inputs*h, axis=1).dimshuffle(0, 'x') - o) / T.sum(h*h, axis=1).dimshuffle(0, 'x'), 1) 22 return inputs - 2 * h * f